package cn.cloud.jianghai.userservice.controller;

import cn.cloud.jianghai.jianghaicommon.entity.R;
import cn.cloud.jianghai.jianghaicommon.utils.ConvertUtil;
import cn.cloud.jianghai.orderapi.entity.OrderDto;
import cn.cloud.jianghai.userapi.dto.UserDto.UserDto;
import cn.cloud.jianghai.userservice.query.UserQuery;
import cn.cloud.jianghai.userservice.service.UserService;
import cn.cloud.jianghai.userservice.vo.UserVo;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Jiang.h
 * created 2022/5/21 18:20
 */
@RestController
@RequestMapping("/v1/user/")
@RequiredArgsConstructor
public class UserController {

    private final UserService userService;

    /**
     *  查找用户列表
     * @param query 查询参数
     * @Date 2022/5/22 17:00
     * @Author Jiang.h
     * @return cn.cloud.jianghai.orderapi.entity.R<java.util.List<cn.cloud.jianghai.userservice.vo.UserVo>>
     **/
    @GetMapping("/findUserList")
    public R<List<UserVo>> findUserList(UserQuery query) {

        return R.success(userService.findUserList(query));
    }

    /**
     *  新增
     * @param userVo 数据体
     * @Date 2022/5/22 17:37
     * @Author Jiang.h
     * @return cn.cloud.jianghai.orderapi.entity.R<java.lang.Boolean>
     **/
    @PostMapping("/insert")
    public R<Boolean> insert(@RequestBody UserVo userVo) {

        return R.success(userService.insert(ConvertUtil.copyBeanProperties(userVo, UserDto.class)));
    }


    @GetMapping("/testHystrix")
    public R<List<OrderDto>> testHystrix(Long id) {

        return R.success(userService.testHystrix(id));
    }
}
